"use strict";

var book = {
    name: '大前端',
    age: 22
};
var proxy = new Proxy(book, {
    get: function get(target, propKey) {
        if (propKey in target) {
            // console.log(book);
            //target就是book对象，propKey就是属性名
            console.log(target);
            console.log(propKey);
            return target[propKey];
        } else {
            throw new ReferenceError("Prop name \"" + propKey + "\" does not exist.");
        }
    },
    set(target, property, value) {
        console.log('value :', value); //set传过去的值
        console.log('property :', property); //property是属性名
        console.log('target :', target); //target是原属性对象
        console.log(`target's ${property} change to ${value}`);
        target[property] = value;
        return true;
    }
});

// console.log(proxy.name);
// console.log('\n')
// proxy.age = 55;
// console.log('proxy.age :', proxy.age);

let arr = [1, 2, 3]
let proxy_ = new proxy(arr, {
    get(target, key, receiver) {
        console.log('get :', key);
        return Reflect.get(target, key, receiver);
    },
    set(target,key,value,receiver){
    console.log('set :',key,value);
    

    }
})